package com.yazi.mxz.common.db.dao.impl;


import java.util.HashMap;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.yazi.mxz.common.db.dao.NoticeDao;
import com.yazi.mxz.common.entity.beans.Notice;

import com.myframework.smhj.hibernate.dao.BasicDao;

@Repository("noticeDao")
public class NoticeDaoImpl extends BasicDao<Notice> implements NoticeDao {


	public NoticeDaoImpl() {
		super(Notice.class);
		
	}

	@Override
	public Criteria getExample(Notice notice, String searchWord) {
		Criteria c = super.getExample(notice, searchWord);
		
		// ...关联对象条件
		
		// 关键字条件
		if(null != searchWord && !searchWord.isEmpty()){
			//关键字可查标题、摘要、正文
			String likeWord = "%" + searchWord + "%";
			c.add(Restrictions.or(
					Restrictions.like("title", likeWord),
					Restrictions.or(Restrictions.like("summary", likeWord),
							Restrictions.like("content", likeWord))));
		}
		return c;
	}

	@Override
	public int deleteLonely(long[] noticeIds) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("noticeIds", noticeIds);
		return executeUpdate("delLonelyByNoticeIdsHql", map);
	}
}
